//
//  ProgressViewController.m
//  BrokenLine
//
//  Created by Rookie_YX on 16/10/19.
//  Copyright © 2016年 Rookie_YX. All rights reserved.
//

#import "ProgressViewController.h"
#import "YXProgressView.h"
@interface ProgressViewController ()

@end

@implementation ProgressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  m_timeSelected = 0;
  
  m_ProgressBar = [[YXProgressView alloc] initWithFrame:self.view.bounds];
  m_ProgressBar.delegate = self;
  [m_ProgressBar setTotalSecondTime:0];
  [self.view addSubview:m_ProgressBar];
  
  //单击开始
  UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapDetected)];
  singleTap.numberOfTapsRequired = 1;
  [m_ProgressBar setUserInteractionEnabled:YES];
  [m_ProgressBar addGestureRecognizer:singleTap];
  //双击暂停
  UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapDetected)];
  doubleTap.numberOfTapsRequired = 2;
  [m_ProgressBar addGestureRecognizer:doubleTap];

}

- (void)singleTapDetected{
  CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
  MyTimePicker *timePicker = [[MyTimePicker alloc] initWithFrame:CGRectMake(0, 0,400, 400)];
  [timePicker setDelegate:self];
  
  [alertView setContainerView:timePicker];
  [alertView setDelegate:self];
  [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"确定", @"取消", nil]];
  [alertView show];

}
- (void)doubleTapDetected {
  [m_ProgressBar pauseTimer];
}
#pragma mark - progress bar delegate
- (void)CircularProgressEnd {
  [m_ProgressBar stopTimer];
  m_timeSelected = 0;
}

#pragma mark - picker delegate
- (void)timeSelected:(int)minute {
  m_timeSelected = minute;
}

#pragma mark - popup delegate
- (void)customIOS7dialogButtonTouchUpInside: (CustomIOSAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
  if (buttonIndex == 0) {
    [m_ProgressBar setTotalMinuteTime:m_timeSelected];
    [m_ProgressBar startTimer];
  }
  [alertView close];
}

@end
